# -*- coding: utf-8 -*-
"""
__mktime__ = '2019/4/13'
__author__ = 'Just'
__filename__ = '__init__.py'
"""
from .app import Flask


def register_blueprint(_app):
    """注册蓝图"""
    from app.api.v1 import create_blueprint_v1
    from app.api.cms import create_blueprint_cms
    _app.register_blueprint(create_blueprint_v1(), url_prefix='/api/v1')
    _app.register_blueprint(create_blueprint_cms(), url_prefix='/api/cms')


def register_plugin(_app):
    """注册插件 放在最后"""
    from app.model.base import db
    # 先导入创建数据关系表
    from app.model.user import User
    from app.model.comic import Comic
    from app.model.comic_latest import ComicLatest
    from app.model.comic_section import ComicSection
    from app.model.comic_image import ComicImage
    from app.model.read_record import ReadRecord
    from app.model.banner import Banner
    from app.model.banner_item import BannerItem
    from app.model.theme import Theme

    db.init_app(_app)
    with _app.app_context():
        db.create_all()


def create_app():
    _app = Flask(__name__)
    _app.config.from_object('app.config.setting')
    _app.config.from_object('app.config.secure')

    register_blueprint(_app)

    register_plugin(_app)
    return _app



